//package cn.th.config;
//
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.annotation.JsonTypeInfo;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.DeserializationFeature;
//import com.fasterxml.jackson.databind.MapperFeature;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.SerializationFeature;
//import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
//import org.springframework.data.redis.serializer.RedisSerializer;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
//import javax.annotation.Resource;
//import java.text.SimpleDateFormat;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.TimeZone;
//
//@Configuration
//public class MyRedisConfig {
//
////    @Resource
////    private RedisConnectionFactory connectionFactory;
//
////    @Bean
////    public RedisTemplate redisTemplate(){
////        RedisTemplate<String, Object> template = new RedisTemplate<>();
////        template.setConnectionFactory(connectionFactory);
////
////        template.setKeySerializer(new StringRedisSerializer());
////
////        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
////        template.setValueSerializer(jackson2JsonRedisSerializer);
////
////        ObjectMapper om = new ObjectMapper();
////        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
////        om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH: mm :ss"));
////        om.setTimeZone(TimeZone.getDefault());
////        om.configure(MapperFeature.USE_ANNOTATIONS, false);
////        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
////        om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
////        om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance ,ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
////        om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
////
////        jackson2JsonRedisSerializer.setObjectMapper(om);
////
////        return template;
////    }
////    @Bean
////    public RedisTemplate<String, Object> redisTemplate() {
////        RedisTemplate<String, Object> template = new RedisTemplate<>();
////        template.setConnectionFactory(connectionFactory);
////
////        template.setKeySerializer(new StringRedisSerializer());
////
////        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
////        template.setValueSerializer(jackson2JsonRedisSerializer);
////
////        ObjectMapper om = new ObjectMapper();
////        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
////        om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
////        om.setTimeZone(TimeZone.getDefault());
////        om.configure(MapperFeature.USE_ANNOTATIONS, false);
////        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
////        om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
////        om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
////        om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
////
////        // 添加对LocalDateTime的处理
////        om.registerModule(new JavaTimeModule());
////        om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
////
////        jackson2JsonRedisSerializer.setObjectMapper(om);
////
//////        template.setValueSerializer(jackson2JsonRedisSerializer);
//////        template.setHashValueSerializer(jackson2JsonRedisSerializer);
////
////        template.afterPropertiesSet();
////
////        return template;
////    }
//
//}
